<template>
    <list-layout>
        <div slot="search">
            <el-form :model="queryParams" :inline="true" ref="queryForm" v-show="showSearch" label-width="88px">

                <el-form-item :label="$t('inspectionManagement.inspectNo')" prop="lot">
                    <el-input v-model="queryParams.inspectionOrder" :placeholder="$t('public.placeholder',{placeholder: $t('inspectionManagement.inspectNo')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                    <el-input v-model="queryParams.materialName" :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.materialName')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                    <el-input v-model="queryParams.supplierCode" :placeholder="$t('public.placeholder',{placeholder: $t('inventoryManagement.supplierNo')})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inspectionManagement.inspectionTime')" prop="inspectionTime">
                    <el-date-picker style="width: 214px" v-model="queryParams.inspectionTime" size="small" type="daterange" value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div style="display:flex;justify-content: center;">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('public.search')}}</el-button>
                <el-button icon="el-icon-refresh" class="resectBtn" size="mini" @click="resetQuery">{{$t('public.reset')}}</el-button>
            </div>
        </div>
        <div class="app-container">
            <div class="container-header">
                <div class="header-left">
                    {{$t('inventoryManagement.destructiveAccount')}}
                </div>
            </div>
            <el-row :gutter="10" class="mb8 btnGroup">
                <el-col :span="1.5">
                    <el-button size="mini" class="exportitemBtn" v-hasPermi="['ny-iqc:exemption:export']" @click="handleExport"><img src="@/assets/images/icons/daochu.png" alt=""> {{$t('public.export')}}</el-button>
                </el-col>
                <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
            </el-row>

            <div class="container-table">
                <el-table :height="tableHeight" border stripe v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
                    <el-table-column :label="$t('inspectionManagement.inspectNo')" align="left" prop="inspectionOrder" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.materialName')" align="left" prop="materialName" width="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.materialNo')" align="left" prop="materialCode" width="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.supplierName')" align="left" prop="supplierName" min-width="120" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.supplierNo')" align="left" prop="supplierCode" min-width="120" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.factory')" align="left" prop="factoryName" min-width="120" :show-overflow-tooltip="true" />
                    <el-table-column label="送检时间" align="left" prop="deliveryDate" min-width="120" :show-overflow-tooltip="true" />
                    <el-table-column label="检验员" align="left" prop="tionInspectorName" min-width="120" :show-overflow-tooltip="true" />

                    <el-table-column :label="$t('inventoryManagement.destructiveQuantity')" align="left" prop="destroyAmount" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.unit')" align="left" prop="unit" :show-overflow-tooltip="true" />
                </el-table>

                <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" layout="total, sizes, prev, pager, next, jumper" />
            </div>

        </div>
    </list-layout>
</template>

<script>
import { listDestroy } from '@/api/inventoryManagement/inspectedInventory'
import { mapGetters, mapState } from 'vuex'
export default {
    name: 'destructiveAccount',
    dicts: ['sys_normal_disable'],
    computed: {
        ...mapState({
            isFold: (state) => state.app.isFold,
        }),
    },
    watch: {
        isFold(val) {
            if (val === true) {
                this.tableHeight = 'calc(100vh - 308px)'
            } else {
                this.tableHeight = 'calc(100vh - 396px)'
            }
        },
    },
    data() {
        return {
            direction: 'rtl',
            addInspection: false,
            drawer: false,
            approvalOpen: false,
            viewModel: {
                inspectionInformation: '0',
            },
            editModel: {
                inspectionInformation: '0',
            },
            approvalForm: {
                status: '1',
                textarea: '',
            },
            tableHeight: 'calc(100vh - 308px)',
            selBtn: 1,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                supplierBatchNo: undefined,
                lot: undefined,
                materialName: undefined,
                supplierCode: undefined,
                createTime: undefined,
                params: {
                    beginTime: '',
                    endTime: '',
                },
                inspectionTime: [],
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                dictName: [
                    {
                        required: true,
                        message: '字典名称不能为空',
                        trigger: 'blur',
                    },
                ],
                dictType: [
                    {
                        required: true,
                        message: '字典类型不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
        }
    },
    created() {
        this.getList()
    },
    methods: {
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            let params = { ...this.queryParams }
            if (params.inspectionTime.length) {
                params.params.beginTime = params.inspectionTime[0]
                params.params.endTime = params.inspectionTime[1]
            } else {
                params.params.beginTime = ''
                params.params.endTime = ''
            }
            delete params.inspectionTime
            listDestroy(params).then((response) => {
                if (response.code == 200 && response.rows) {
                    this.typeList = response.rows
                    this.total = response.total
                    this.loading = false
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            this.addInspection = true
        },
        handleApproval() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            this.approvalOpen = true
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.open = false
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 删除按钮操作 */
        handleDelete(row) {
            const dictIds = row.noticeId || this.ids
            this.$modal
                .confirm('是否确认删除消息编号为"' + dictIds + '"的数据项？')
                .then(function () {
                    return deleteNotice(dictIds)
                })
                .then(() => {
                    this.getList()
                    this.$modal.msgSuccess(this.$t('processDefinition.successfullyDeleted'))
                })
                .catch(() => {})
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.open = true
            if (row.hasRead == 0) {
                readNotice(row.noticeId).then((res) => {
                    if (res.code == 200) {
                        this.handleQuery()
                    }
                })
            }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            this.drawer = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            let params = { ...this.queryParams }
            if (params.inspectionTime.length) {
                params.params.beginTime = params.inspectionTime[0]
                params.params.endTime = params.inspectionTime[1]
            } else {
                params.params.beginTime = ''
                params.params.endTime = ''
            }
            delete params.inspectionTime
            this.download(
                'ny-iqc/destroy/export',
                params,
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
    border-bottom: 2px solid #0b7be3;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
</style>
